package demo;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class BinaryDemo {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入你想转换成二进制的数字");
        int input = scan.nextInt();
        System.out.println("系统自动编译输出的二进制");
        System.out.println(Integer.toBinaryString(input));
        System.out.println("我们编译输出的二进制数");
        List<Integer> list = new ArrayList<>();
        int index = 0;
        for ( ; index< 32; index++) {
            if (input!=0){
                list.add(index,input%2);
                input /= 2;
            }else {
                break;
            }
        }
        for (index = index-1 ;  index>=0 ; index--) {
            System.out.print(list.get(index));
        }

        System.out.println();
        System.out.println("-----------");
        System.out.println("请输入你想转换成十六进制的数字");
        long inputs = scan.nextLong();
        System.out.println("系统自动编译输出的十六进制");
        System.out.println(Long.toHexString(inputs));
        System.out.println("我们编译输出的十六进制数");
        List<String> list1 = new ArrayList<>();
        index = 0;
        for (;index<64;index++){
            if(inputs != 0){
                    switch ((int)(inputs %16)){
                        case 1:
                            list1.add(index,"1");
                            break;
                        case 2:
                            list1.add(index,"2");
                            break;
                        case 3:
                            list1.add(index,"3");
                            break;
                        case 4:
                            list1.add(index,"4");
                            break;
                        case 5:
                            list1.add(index,"5");
                            break;
                        case 6:
                            list1.add(index,"6");
                            break;
                        case 7:
                            list1.add(index,"7");
                            break;
                        case 8:
                            list1.add(index,"8");
                            break;
                        case 9:
                            list1.add(index,"9");
                            break;
                        case 10:
                            list1.add(index,"a");
                            break;
                        case 11:
                            list1.add(index,"b");
                            break;
                        case 12:
                            list1.add(index,"c");
                            break;
                        case 13:
                            list1.add(index,"d");
                            break;
                        case 14:
                            list1.add(index,"e");
                            break;
                        case 15:
                            list1.add(index,"f");
                            break;
                    }
                    inputs /=16;
            }else {
                break;
            }
        }

        for (index = index-1 ;  index>=0 ; index--) {
            System.out.print(list1.get(index));
        }




    }
}
